package com.wpml.orm;

import java.sql.ResultSet;

public class QueryOneHandler<T> implements OrmHandler<T>{

    Class<T> clazz;

    public QueryOneHandler(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public T handler(ResultSet rs) throws Exception{

        if (rs == null) {
            return null;
        }

        int[] ints = JdbcUtils.column2Property(rs, clazz.getDeclaredFields());

        if (rs.next()) {
           return JdbcUtils.result2PO(rs, ints, clazz);
        }

        return null;
    }
}
